package com.ruoyi.lc.biz.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lc.biz.domain.BizType;
import com.ruoyi.lc.biz.service.IBizTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 业务类型Controller
 *
 * @author qibotian
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/lc/biz")
public class BizTypeController extends BaseController {
    @Autowired
    private IBizTypeService bizTypeService;

    /**
     * 查询业务类型列表
     */
    @PreAuthorize("@ss.hasPermi('lc:biz:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizType bizType) {
        startPage();
        QueryWrapper<BizType> queryWrapper = new QueryWrapper<BizType>(bizType);
        List<BizType> list = bizTypeService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询业务类型列表
     */
    @PreAuthorize("@ss.hasPermi('lc:biz:query')")
    public AjaxResult all() {
        QueryWrapper<BizType> queryWrapper = new QueryWrapper<BizType>();
        List<BizType> list = bizTypeService.list(queryWrapper);
        return AjaxResult.success(list);
    }

    /**
     * 导出业务类型列表
     */
    @PreAuthorize("@ss.hasPermi('lc:biz:export')")
    @Log(title = "业务类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizType bizType) {
        QueryWrapper<BizType> queryWrapper = new QueryWrapper<BizType>(bizType);
        List<BizType> list = bizTypeService.list(queryWrapper);
        ExcelUtil<BizType> util = new ExcelUtil<BizType>(BizType.class);
        util.exportExcel(response, list, "业务类型数据");
    }

    /**
     * 获取业务类型详细信息
     */
    @GetMapping(value = "/getInfoByCode/{code}")
    public AjaxResult getInfoByCode(@PathVariable("code") String code) {
        return success(bizTypeService.queryByCode(code));
    }

    /**
     * 获取业务类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('lc:biz:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizTypeService.getById(id));
    }

    /**
     * 新增业务类型
     */
    @PreAuthorize("@ss.hasPermi('lc:biz:add')")
    @Log(title = "业务类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizType bizType) {
        return toAjax(bizTypeService.save(bizType));
    }

    /**
     * 修改业务类型
     */
    @PreAuthorize("@ss.hasPermi('lc:biz:edit')")
    @Log(title = "业务类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizType bizType) {
        return toAjax(bizTypeService.saveOrUpdate(bizType));
    }

    /**
     * 删除业务类型
     */
    @PreAuthorize("@ss.hasPermi('lc:biz:remove')")
    @Log(title = "业务类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizTypeService.removeByIds(Arrays.asList(ids)));
    }
}
